<html>
<head>
<title>管理系统</title>
<meta http-equiv=Content-Type content=text/html;charset=utf-8>
<#include "/xadmin/inc/common.html">
<script type="text/javascript">
//页面加载  
var grid;
$(function(){  
	//加载数据  
    grid = $('#rolegrid').datagrid({  
        url:'qxmanage-listrole',  
        //queryParams:{},  
        loadMsg:'数据加载中请稍后……',  
         striped: true,  
         singleSelect : true,  
         pagination: true,  
         rownumbers: true,     
         pageSize: [${syscfg.pageSize!10}],
         pageList: [${syscfg.pageList!10}],
         columns:[[  
             {field:'jsdm',title: '角色代码',align: 'center',width: '200'},  
             {field:'jsmc',title: '角色名称',align: 'center',width: '200'},
             {field:'action',title: '权限操作',align: 'center',width: '250',
             formatter: function(value,rowdata,index){
             		var str = '<a id="btnadd" class="l-btn l-btn-plain" href="javascript:installRole(\''+rowdata.jsdm+'\')"><span class="l-btn-left"><span class="l-btn-text icon-cut l-btn-icon-left">设置权限</span></span></a>';
					str += '<a id="btnadd" class="l-btn l-btn-plain" href="javascript:showRole(\''+rowdata.jsdm+'\')"><span class="l-btn-left"><span class="l-btn-text icon-search l-btn-icon-left">查看权限</span></span></a>';
					return str;
				}
             },
             {field:'zt',title: '状态',align: 'center',width: '100',
              	formatter: function(value,rowdata,index){
              		var str = '';
 					if(value ==0){
 						str += '<a id="btnstate" class="l-btn l-btn-plain" href="javascript:jinyong(\''+rowdata.jsdm+'\',\''+value+'\')"><span class="l-btn-left"><span class="l-btn-text icon-no l-btn-icon-left">启用</span></span></a>';
 					}else{
 						str += '<a id="btnstate" class="l-btn l-btn-plain" href="javascript:jinyong(\''+rowdata.jsdm+'\',\''+value+'\')"><span class="l-btn-left"><span class="l-btn-text icon-ok l-btn-icon-left">禁用</span></span></a>';
 					}
 					return str;
 				}
              }
         ]],
         toolbar : [btn_add,btn_edit,btn_del,"-"],
		onDblClickCell: function(index,field,value){
			var jsdm = $('#rolegrid').datagrid('getData').rows[index].jsdm;
			showRole(jsdm);
		} 
    });
    $("#tree").tree({
        method: "post",
        lines: true,
        url: "qxmanage-listjsfortree?flag=true&jsdm=admin",
        dataPlain: true,       //该属性用以启用当前 easyui-tree 控件对平滑数据格式的支持
        toggleOnClick: false,
        //checkbox: true,
        enableContextMenu: false
    });
});  
	function showRole(jsdm) {
		$("#tree").tree('options').url = "${request.contextPath}/xadmin/system/qxmanage-listjsfortree?flag=true&jsdm="+jsdm;
		$("#tree").tree('reload');
	}
	//新增角色
	function doAdd() {
		var url = '${request.contextPath}/xadmin/system/qxmanage-rolewindow';
		top.modalwindow(url , grid,{ width:550,height:180,title:'新增角色信息'});
	}	
	//工具栏修改角色
	function doEdit() {
		var selected = grid.datagrid('getSelected');
		if(!selected){
			$.messager.alert('提示',"请选择相关数据进行操作！");
			return;
		}
		var url = '${request.contextPath}/xadmin/system/qxmanage-rolewindow?jsdm='+selected.jsdm;
		top.modalwindow(url, grid,{ width:550,height:180,title:'修改角色信息'});
	}
	//工具栏删除角色
	function doDel(){
		var selected = grid.datagrid('getSelected');
		if(!selected){
			$.messager.alert('提示',"请选择相关数据进行操作！");
			return;
		}
		$.messager.confirm('系统提示', '<br>&nbsp;&nbsp;&nbsp;&nbsp;你确定要删除该信息?', function(r) {
			if (r) {
				$.post("qxmanage-delrole", { "jsdm": selected.jsdm},
				   function(data){
				   	grid.datagrid('reload'); 
				   	$.messager.alert('提示',data);		   	
				});
			}
		});
	}
	// 设置角色权限
	function installRole(jsdm){
		var url = '${request.contextPath}/xadmin/system/qxmanage-setrolewindow?jsdm='+jsdm;
		top.modalwindow(url, grid,{ width:550,height:400,title:'设置角色信息'});
	}
	//
	function jinyong(jsdm, result){
		if(result==0){
			result = 1;
		}else{
			result = 0;
		}
		$.post("qxmanage-updaterolezt", {"jsdm": jsdm, "zt":+result},
		   	function(data){
		   		grid.datagrid('reload'); 
		   		top.messagershow(data);
		});
	}
</script>

</head>
<body class="easyui-layout">
<div data-options="region:'east',iconCls:'icon-mini-add',title:'显示权限',split:true" style="width:200px;">
	<div class="easyui-panel" data-options='fit:true,border:false'> 
		<ul id="tree"></ul>
	</div>
</div>   
<div data-options="region:'center'">
<table id="rolegrid" data-options="fit:true,border:false"></table>
</div>
</body>
</html>